package ch03;

public class Example3_4 {//汉诺塔
    private int c = 0;

    public void hanoi(int n, char x, char y, char z){
        if (n == 1) {
            move(x, 1, z);
        }else{
            hanoi(n-1, x, z, y );
            move(x, n, z);
            hanoi(n - 1,y, x,z);
        }
    }

    public void move(char x, int n, char z) {
        System.out.println("第"+ ++c + "次移动" + n + "号圆盘，" + x + "->" + z);
    }

    public static void main(String[] args) {
        Example3_4 h = new Example3_4();
        h.hanoi(3, 'x' , 'y', 'z');
    }
}
